package cn.liumouren.tool.pac.entity;

import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

/**
 * @author Daniel Liu
 * @date 2021/1/3 20:39
 */
public class PageResult {
    /**
     * 总记录数
     */
    private Integer totalCount;
    /**
     * 当前页数
     */
    private Integer curPage;
    /**
     * 每页记录数
     */
    private Integer pageSize;
    /**
     * 总页数
     */
    private Integer totalPage;
    /**
     * 列表数据
     */
    private List<?> list;

    /**
     * 分页
     *
     * @param list       列表数据
     * @param totalCount 总记录数
     * @param pageSize   每页记录数
     * @param curPage   当前页数
     */
    public PageResult(List<?> list, int totalCount, int pageSize, int curPage) {
        this.list = list;
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.curPage = curPage;
        if (pageSize <= 0) {
            this.totalPage = 0;
        } else {
            this.totalPage = (int) Math.ceil((double) totalCount / pageSize);
        }
    }

    /**
     * 分页
     */
    public PageResult(IPage<?> page) {
        this.list = page.getRecords();
        this.totalCount = (int) page.getTotal();
        this.pageSize = (int) page.getSize();
        this.curPage = (int) page.getCurrent();
        this.totalPage = (int) page.getPages();
    }

    public Integer getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(Integer totalCount) {
        this.totalCount = totalCount;
    }

    public Integer getCurPage() {
        return curPage;
    }

    public void setCurPage(Integer curPage) {
        this.curPage = curPage;
    }

    public Integer getPageSize() {
        return pageSize;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public Integer getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public List<?> getList() {
        return list;
    }

    public void setList(List<?> list) {
        this.list = list;
    }
}
